home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Financial / USDebtWatch / unix-version / xdebt-xcerpt.c < prev    next >
C/C++ Source or Header  |  1995-06-12  |  3KB  |  105 lines

  1. /* most of this file is excerpted from Jamie Zawinski's xdebt program.
  2.    Jamie Zawinski is <jwz@lucid.com>. Public Domain.
  3.  
  4.    Mods by Erik Sowa (sowa@netcom.com).
  5.    
  6.    I have replaced the call to 'timelocal,' which I could not locate,
  7.    with a call to Oliver Laumann's tm_to_time, which I obtained from
  8.    Volume 4 of the comp.unix.sources archives.
  9.  
  10.    More mods by sonroc@nemesis.zycad.com [a/k/a twk@zycad.com] to include
  11.    per-capita.
  12.  
  13. */
  14.  
  15. #include <time.h>
  16. #include <stdio.h>
  17. extern time_t tm_to_time();
  18.  
  19.  
  20. /* older debt estimate */
  21. /* The US National Debt, and its rate of increase as of December 31, 1988
  22.    (in dollars per second) according to the 1989 Survey of Current Business.
  23. .  These values are floats because they're >42 bits.
  24.  */
  25.  
  26. typedef double debt_t, pop_t;
  27. #define SCB89DEBT  2707284000000.0
  28. #define SCB89DELTA 7673.015
  29. static struct tm scb89debt_tm = { 0, 0, 0, 31, 11, 88 }; /* Dec. 31, 1988 */
  30.  
  31.  
  32. /* newer debt estimate */
  33. /* The US National Debt, and its rate of increase as of June 30, 1992      */
  34. /* (in $/second) based on numbers from the 5 July 1992 Albuquerque Journal */
  35. /*  .... thanks to Brooke King brooke@fuchsia.albuq.ingr.com               */
  36. #define AJ92DEBT    3965170506502.395    /* in dollars */
  37. #define AJ92DELTA    14132.887        /* Dollars per second */
  38. static struct tm aj92debt_tm = { 0, 0, 0, 30, 05, 92 };
  39.  
  40.  
  41. /* The US Population, and its rate of increase, as of July 1, 1990        */
  42. /* (in people/second) based on numbers from the CIA's World Factbook 1990 */
  43. /*  .... thanks to tom@genie.slhs.udel.edu                                */
  44. #define POP          250410000.0            /* people */
  45. #define POP_DELTA    0.0714151266        /* increase in people per second */
  46. static struct tm pop_tm = { 0, 0, 0, 1, 6, 90 };
  47.  
  48.  
  49. debt_t
  50. national_scb89debt_at (now)
  51.      time_t now;
  52. {
  53.   time_t debt_date = tm_to_time(&scb89debt_tm);
  54.   time_t seconds_since_then = now - debt_date;
  55.   debt_t delta_since_then = SCB89DELTA * seconds_since_then;
  56.   return SCB89DEBT + delta_since_then;
  57. }
  58.  
  59.  
  60. debt_t
  61. national_aj92debt_at (now)
  62.      time_t now;
  63. {
  64.   time_t debt_date = tm_to_time(&aj92debt_tm);
  65.   time_t seconds_since_then = now - debt_date;
  66.   debt_t delta_since_then = AJ92DELTA * seconds_since_then;
  67.   return AJ92DEBT + delta_since_then;
  68. }
  69.  
  70.  
  71. pop_t
  72. national_pop_at (now)
  73.      time_t now;
  74. {
  75.   time_t pop_date = tm_to_time(&pop_tm);
  76.   time_t seconds_since_then = now - pop_date;
  77.   pop_t delta_since_then = POP_DELTA * seconds_since_then;
  78.   return POP + delta_since_then;
  79. }
  80.  
  81.  
  82. extern char *index ();
  83.  
  84. void
  85. debt_to_string (debt, s)
  86.      debt_t debt;
  87.      char *s;
  88. {
  89.   int L, i = 0;
  90.   char buf [255];
  91.   char *b = buf;
  92.   sprintf (b, "%lf\0", debt);
  93.   b = index (b, '.') - 1;
  94.   L = b - buf;
  95.   s += L + (L / 3);
  96.   *(s+1) = 0;
  97.   i = -1;
  98.   while (1)
  99.     {
  100.       if (++i == 3) i = 0, *s-- = ',';
  101.       if (b < buf) return;
  102.       *s-- = *b--;
  103.     }
  104. }
  105.